//
//  CTSubjectDetailView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/5.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTSubjectDetailView.h"
#import "CTDebugManager.h"
#import "CTDeviceFunction.h"
#import "CTHeader.h"
#import "CTSubjectDetailCell.h"
#import "UIViewAdditions.h"
#import "CTAppLanguage.h"
#import "CTRequestUtil.h"
#import "CTUser.h"
#import "CTHomePageItems.h"
#import "CTTextManager.h"
#import "CTLogin.h"

@interface CTSubjectDetailView()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    CGSize              size;
    UICollectionView    *subjectCollectionView;
    UIView              *subjectHeaderView;
    UIView              *topView;
    UILabel             *titleLabel;
    UIImageView         *userHeaderImageView;
    UILabel             *userNameLabel;
    UILabel             *timeLabel;
    UILabel             *describeLabel;
    UILabel             *firstLabel;
    UILabel             *secondLabel;
    UILabel             *thridLabel;
    UIImageView         *firstImageView;
    UIImageView         *secondImageView;
    UIImageView         *thridImageView;
    UILabel             *headerLine;
    UIButton            *cameraBtn;
    UIButton            *attentionBtn;
    UILabel             *attentionLabel;
    BOOL                attention_bool;
    CTSubjectItem       *currentSelectedItem;
}

@end

@implementation CTSubjectDetailView

@synthesize delegate,subjectDetailArray;

- (void)dealloc
{
    delegate = nil;
    currentSelectedItem = nil;
    subjectDetailArray = nil;
    [subjectCollectionView removeFromSuperview];
    subjectCollectionView = nil;
    [subjectCollectionView removeFromSuperview];
    subjectCollectionView = nil;
    [topView removeFromSuperview];
    topView = nil;
    [titleLabel removeFromSuperview];
    titleLabel = nil;
    [userHeaderImageView removeFromSuperview];
    userHeaderImageView = nil;
    [timeLabel removeFromSuperview];
    timeLabel = nil;
    [describeLabel removeFromSuperview];
    describeLabel = nil;
    [firstImageView removeFromSuperview];
    firstImageView = nil;
    [firstLabel removeFromSuperview];
    firstLabel = nil;
    [secondImageView removeFromSuperview];
    secondImageView = nil;
    [secondLabel removeFromSuperview];
    secondLabel = nil;
    [thridImageView removeFromSuperview];
    thridImageView = nil;
    [thridLabel removeFromSuperview];
    thridLabel = nil;
    [headerLine removeFromSuperview];
    headerLine = nil;
    [cameraBtn removeFromSuperview];
    cameraBtn = nil;
    [attentionBtn removeFromSuperview];
    attentionBtn = nil;
    [attentionLabel removeFromSuperview];
    attentionLabel = nil;
//    userPublishArray = nil;
    [CTDebugManager showDebugLogInfo:@"dealloc : CTUserPublishCollectionListView Is Removed!!!"];
    
}

- (instancetype)initWithFrame:(CGRect)frame withItem:(CTSubjectItem *) item
{
    self = [super initWithFrame:frame];
    if (self)
    {
        currentSelectedItem = item;
        subjectDetailArray = item.list;
        [self createRegisterTitlView];
        [self createHeaderView];
        [self createUserCollectionView];
        DeviceTypeAdaptation adapation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
        switch (adapation) {
            case iPhone4_4s:
                size = CGSizeMake((CT_HEADER_SCREEN_WIDTH-105)/3, (CT_HEADER_SCREEN_WIDTH-105)/3);
                break;
            case iPhone5_5s_5c:
                size = CGSizeMake((CT_HEADER_SCREEN_WIDTH-105)/3, (CT_HEADER_SCREEN_WIDTH-105)/3);
                break;
            case iPhone6:
                size = CGSizeMake((CT_HEADER_SCREEN_WIDTH-105)/3, (CT_HEADER_SCREEN_WIDTH-105)/3);
                break;
            case iPhone6_Plus:
                size = CGSizeMake((CT_HEADER_SCREEN_WIDTH-105)/3, (CT_HEADER_SCREEN_WIDTH-105)/3);
                break;
            default:
                break;
        }
    }
    return self;
}

//标题
- (void)createRegisterTitlView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self addSubview:topView];
    
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text  = currentSelectedItem.group_name;
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.font = [UIFont fontWithName:nil size:19];
    [topView addSubview:titleLabel];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    [topView addSubview:backButton];
    
    UIButton *shareButton =[UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-44, 20, 44, 44);
    [shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [shareButton setTitleColor:CT_HEADER_WHITE_COLOR forState:UIControlStateNormal];
    [shareButton setImage:[UIImage imageNamed:@"biaotilan_bt_share"] forState:UIControlStateNormal];
    [shareButton setImage:[UIImage imageNamed:@"biaotilan_bt_share_click"] forState:UIControlStateHighlighted];
    [topView addSubview:shareButton];
    UILabel *titleBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    titleBottomLine.backgroundColor =CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:titleBottomLine];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
}
- (float)LabelHeightLabel:(UILabel*)label fontSize:(float)fontSize
{
    
    CGSize  titleSize = [label.text sizeWithFont:[UIFont systemFontOfSize:fontSize]
                               constrainedToSize:CGSizeMake(CT_HEADER_SCREEN_WIDTH-20, 2000)
                                   lineBreakMode:NSLineBreakByCharWrapping];
    label.frame = CGRectMake(label.frame.origin.x,
                             label.frame.origin.y,
                             label.frame.size.width,
                             titleSize.height);
    return titleSize.height;
}

//创建HeaderView
- (void)createHeaderView
{
    subjectHeaderView = [[UIView alloc]init];
    
    
    userHeaderImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 45, 45)];
    userHeaderImageView.layer.masksToBounds = YES;
    userHeaderImageView.image = [UIImage imageNamed:@"head"];
    userHeaderImageView.layer.cornerRadius  = 22.5f;
    userHeaderImageView.userInteractionEnabled = YES;
    [CTRequestUtil requestImgWithUrl:currentSelectedItem.user.profile_image_url_thumb withCompletionSuccessHandler:^(UIImage *img) {
        userHeaderImageView.image = img;
    } withFailedHandler:^(NSError *error) {
        
    }];
    UITapGestureRecognizer *tapGestureHead = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tagGestureHeadAction:)];
    [userHeaderImageView addGestureRecognizer:tapGestureHead];
    [subjectHeaderView addSubview:userHeaderImageView];
    
    
    
    userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(userHeaderImageView.right+10, 25, 200, 15)];
    userNameLabel.text = currentSelectedItem.user.name;
    userNameLabel.textColor = CT_HEADER_BLACK_COLOR;
    userNameLabel.textAlignment = NSTextAlignmentLeft;
    userNameLabel.font = [UIFont systemFontOfSize:15.0f];
    [subjectHeaderView addSubview:userNameLabel];
    
    timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(userHeaderImageView.right+10, userNameLabel.bottom+9, 200, 12)];
    CTTextManager *textManager = [CTTextManager shareInstance];
    timeLabel.text = [textManager timestampToTime:currentSelectedItem.update_time];
    timeLabel.textColor =CT_HEADER_DEEPLINE_COLOR;
    timeLabel.textAlignment = NSTextAlignmentLeft;
    timeLabel.font = [UIFont systemFontOfSize:12.0f];
    [subjectHeaderView addSubview:timeLabel];
    
    describeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, userHeaderImageView.bottom+10, CT_HEADER_SCREEN_WIDTH-20, 15)];
//    describeLabel.backgroundColor = [UIColor redColor];
    describeLabel.text = [NSString stringWithFormat:@"描述：%@",currentSelectedItem.describe];
    describeLabel.textColor = CT_HEADER_DEEPLINE_COLOR;
    describeLabel.textAlignment = NSTextAlignmentLeft;
    describeLabel.lineBreakMode = NSLineBreakByCharWrapping;
    describeLabel.numberOfLines = 0;
    describeLabel.font = [UIFont systemFontOfSize:15.0];
    [subjectHeaderView addSubview:describeLabel];
    
    [self LabelHeightLabel:describeLabel fontSize:15.0f];
    
//    firstImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, describeLabel.bottom+15, 0, 0)];
//    [subjectHeaderView addSubview:firstImageView];
    firstLabel = [[UILabel alloc]init];
    firstLabel.textAlignment = NSTextAlignmentCenter;
    firstLabel.textColor= [UIColor colorWithRed:114/255.0 green:212/255.0 blue:103/255.0 alpha:1.0];
    firstLabel.layer.masksToBounds = YES;
    firstLabel.layer.cornerRadius  = 9;
    CALayer *btnlayer = [firstLabel layer];
    btnlayer.borderColor = [[UIColor colorWithRed:114/255.0 green:212/255.0 blue:103/255.0 alpha:1.0] CGColor];
    btnlayer.borderWidth = 0.5f;
    firstLabel.font = [UIFont systemFontOfSize:12.0f];
    [subjectHeaderView addSubview:firstLabel];
//    NSLog(@"tag_trends = %@",currentSelectedItem.tag_trends);
    if ([currentSelectedItem.tag_trends isEqualToString:@"1"])
    {
//        firstImageView.frame = CGRectMake(firstImageView.origin.x, describeLabel.bottom+15, 35, 18);
//        firstImageView.image = [UIImage imageNamed:@"tag_bg_one_lianggezi"];
        firstLabel.frame = CGRectMake(10, describeLabel.bottom+15, 35, 18);
        firstLabel.text = [CTAppLanguage localizedStringForKey:@"subjectDetailView_tag_trends_text" withValue:nil withTable:@"Language"];
    }
//    else if(item.tag_trends.length == 3)
//    {
//        firstImageView.frame = CGRectMake(firstImageView.origin.x, firstImageView.origin.y, 47.5, 18);
//        firstImageView.image = [UIImage imageNamed:@"tag_bg_one_sangezi"];
//        firstLabel.frame = CGRectMake(firstImageView.origin.x, firstImageView.origin.y, firstImageView.width, firstImageView.height);
//    }

    
//    secondImageView = [[UIImageView alloc]initWithFrame:CGRectMake(firstImageView.right+10, firstImageView.origin.y, 0 , 0)];
//    [subjectHeaderView addSubview:secondImageView];
    secondLabel = [[UILabel alloc]init];
//                   WithFrame:CGRectMake(secondImageView.origin.x, secondImageView.origin.y, secondImageView.width, secondImageView.height)];
    secondLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.textColor= [UIColor colorWithRed:255/255.0 green:183/255.0 blue:87/255.0 alpha:1.0];
    secondLabel.font = [UIFont systemFontOfSize:12.0f];
    secondLabel.layer.masksToBounds = YES;
    secondLabel.layer.cornerRadius  = 9;
    CALayer *btnlayerSecond = [secondLabel layer];
    btnlayerSecond.borderColor = [[UIColor colorWithRed:255/255.0 green:183/255.0 blue:87/255.0 alpha:1.0] CGColor];
    btnlayerSecond.borderWidth = 0.5f;
    [subjectHeaderView addSubview:secondLabel];
//    NSLog(@"tag_official = %@",currentSelectedItem.tag_official);
    if ([currentSelectedItem.tag_official isEqualToString:@"1"])
    {
        if (firstLabel.width == 0)
        {
            secondLabel.frame = CGRectMake(firstLabel.origin.x+10,describeLabel.bottom+15, 35, 18);
            secondLabel.text = [CTAppLanguage localizedStringForKey:@"subjectDetailView_tag_official_text" withValue:nil withTable:@"Language"];
        }
        else
        {
            secondLabel.frame = CGRectMake(firstLabel.right+10,describeLabel.bottom+15, 35, 18);
            secondLabel.text = [CTAppLanguage localizedStringForKey:@"subjectDetailView_tag_official_text" withValue:nil withTable:@"Language"];
        }
        
    }
//    else
//    {
//        if (firstLabel.width == 0)
//        {
//            secondLabel.frame = CGRectMake(firstLabel.origin.x,describeLabel.bottom+15, 35, 18);
//            secondLabel.text = [CTAppLanguage localizedStringForKey:@"subjectDetailView_tag_official_text" withValue:nil withTable:@"Language"];
//        }
//        else
//        {
//            secondLabel.frame = CGRectMake(firstLabel.right+10,describeLabel.bottom+15, 35, 18);
//            secondLabel.text = [CTAppLanguage localizedStringForKey:@"subjectDetailView_tag_official_text" withValue:nil withTable:@"Language"];
//        }
//
//    }

    thridLabel = [[UILabel alloc]init];
    thridLabel.textAlignment = NSTextAlignmentCenter;
    thridLabel.textColor= [UIColor colorWithRed:249/255.0 green:208/255.0 blue:45/255.0 alpha:1.0];
    thridLabel.font = [UIFont systemFontOfSize:12.0f];
    thridLabel.layer.masksToBounds = YES;
    thridLabel.layer.cornerRadius  = 9;
    CALayer *btnlayerThird = [thridLabel layer];
    btnlayerThird.borderColor = [[UIColor colorWithRed:249/255.0 green:208/255.0 blue:45/255.0 alpha:1.0] CGColor];
    btnlayerThird.borderWidth = 0.5f;
    [subjectHeaderView addSubview:thridLabel];
    
    if (currentSelectedItem.tag_describe.length>0)
    {
        if(firstLabel.width ==0)
        {
            thridLabel.frame = CGRectMake(secondLabel.right+10, describeLabel.bottom+15, 35+(currentSelectedItem.tag_describe.length-2)*12, 18);
            thridLabel.text = currentSelectedItem.tag_describe;
        }
        if (secondLabel.width == 0)
        {
//            thridImageView.frame = CGRectMake(firstLabel.right+10, describeLabel.bottom+15, 35, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_lianggezi"];
            thridLabel.frame = CGRectMake(firstLabel.right+10, describeLabel.bottom+15, 35+(currentSelectedItem.tag_describe.length-2)*12, 18);
            thridLabel.text = currentSelectedItem.tag_describe;
        }

        if (firstLabel.width == 0 && secondLabel.width ==0)
        {
//            thridImageView.frame = CGRectMake(firstLabel.origin.x, describeLabel.bottom+15, 35, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_lianggezi"];
            thridLabel.frame = CGRectMake(firstLabel.origin.x+10, describeLabel.bottom+15, 35+(currentSelectedItem.tag_describe.length-2)*12, 18);
            thridLabel.text = currentSelectedItem.tag_describe;
            
        }
        if (firstLabel.width>0 && secondLabel.width>0)
        {
//            thridImageView.frame = CGRectMake(secondLabel.right+10, describeLabel.bottom+15, 35, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_lianggezi"];
            thridLabel.frame = CGRectMake(secondLabel.right+10, describeLabel.bottom+15, 35+(currentSelectedItem.tag_describe.length-2)*12, 18);
            thridLabel.text = currentSelectedItem.tag_describe;
        }
//               thridImageView.frame = CGRectMake(secondImageView.right+10, describeLabel.bottom+20, 35, 18);
//        thridImageView.image = [UIImage imageNamed:@"tag_bg_three_lianggezi"];
//        thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
//        thridLabel.text = item.tag_describe;
    }
//    else if(currentSelectedItem.tag_describe.length >= 3)
//    {
//        if(firstImageView.width ==0)
//        {
//            thridImageView.frame = CGRectMake(secondImageView.right+10, describeLabel.bottom+15, 47.5, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_sangezi"];
//            thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
//            thridLabel.text = currentSelectedItem.tag_describe;
//        }
//        if (secondImageView.width == 0)
//        {
//            thridImageView.frame = CGRectMake(firstImageView.right+10, describeLabel.bottom+15, 47.5, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_sangezi"];
//            thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
//            thridLabel.text = currentSelectedItem.tag_describe;
//        }
//        
//        if (firstImageView.width == 0 && secondImageView.width ==0)
//        {
//            thridImageView.frame = CGRectMake(firstImageView.origin.x, describeLabel.bottom+15, 47.5, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_sangezi"];
//            thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
//            thridLabel.text = currentSelectedItem.tag_describe;
//            
//        }
//        if (firstImageView.width>0 && secondImageView.width>0)
//        {
//            thridImageView.frame = CGRectMake(secondImageView.right+10, describeLabel.bottom+15, 47.5, 18);
//            thridImageView.image = [UIImage imageNamed:@"tag_bg_three_lianggezi"];
//            thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
//            thridLabel.text = currentSelectedItem.tag_describe;
//        }
//
//
////        thridImageView.frame = CGRectMake(secondImageView.right+10, describeLabel.bottom+20, 47.5, 18);
////        thridImageView.image = [UIImage imageNamed:@"tag_bg_three_sangezi"];
////        thridLabel.frame = CGRectMake(thridImageView.origin.x, thridImageView.origin.y, thridImageView.width, thridImageView.height);
////        thridLabel.text = item.tag_describe;
//    }

    
    

    headerLine = [[UILabel alloc]initWithFrame:CGRectMake(0, describeLabel.bottom+48, CT_HEADER_SCREEN_WIDTH, 0.5)];
    headerLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [subjectHeaderView addSubview:headerLine];
    
    
    subjectHeaderView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, headerLine.origin.y+0.5);
    
    
    attentionLabel = [[UILabel alloc]initWithFrame:CGRectMake(CT_HEADER_SCREEN_WIDTH-10-55, 25, 55, 24)];
    attentionLabel.textAlignment = NSTextAlignmentCenter;
    attentionLabel.font = [UIFont systemFontOfSize:12.0f];
    [subjectHeaderView addSubview:attentionLabel];
    attentionBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    attentionBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-10-55, 25, 55, 24);
    [attentionBtn addTarget:self action:@selector(attentionBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [subjectHeaderView addSubview:attentionBtn];
    
    if ([currentSelectedItem.user.following isEqualToString:@"1"])
    {
        attention_bool = YES;
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_ok_bg"] forState:UIControlStateNormal];
        attentionLabel.textColor= CT_HEADER_DEEPLINE_COLOR;
        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attentioned_title" withValue:nil withTable:@"Language"];
        if ([currentSelectedItem.user.uid isEqualToString:[CTUser userInfo].uid])
        {
            attentionBtn.hidden = YES;
            attentionLabel.hidden = YES;
        }

    }
    else
    {
        attention_bool = NO;
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_bg"] forState:UIControlStateNormal];
        attentionLabel.textColor= CT_HEADER_GREEN_COLOR;
        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attention_title" withValue:nil withTable:@"Language"];
        
        if ([currentSelectedItem.user.uid isEqualToString:[CTUser userInfo].uid])
        {
            attentionBtn.hidden = YES;
            attentionLabel.hidden = YES;
        }

    }

    
//    attentionBtn.layer.masksToBounds = YES;
//    attentionBtn.layer.cornerRadius  = 4;
//    [attentionBtn setTitle:[CTAppLanguage localizedStringForKey:@"discoveryView_segment_one" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
//    [attentionBtn setTitleColor:CT_HEADER_MAIN_GREEN_COLOR forState:UIControlStateNormal];
//    [subjectHeaderView addSubview:attentionBtn];
//    CALayer *btnlayer = [attentionBtn layer];
//    btnlayer.borderColor = [CT_HEADER_MAIN_GREEN_COLOR CGColor];
//    btnlayer.borderWidth = 0.5f;
//    [subjectHeaderView addSubview:attentionBtn];
    
}

//创建CollectionView
- (void)createUserCollectionView
{
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    flowLayout.headerReferenceSize = CGSizeMake(CT_HEADER_SCREEN_WIDTH, subjectHeaderView.height);//头部
    subjectCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,topView.bottom, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-topView.height) collectionViewLayout:flowLayout];
    // homePageCollectionView.showsVerticalScrollIndicator = NO;
    subjectCollectionView.delegate = self;
    subjectCollectionView.dataSource = self;
    [self addSubview:subjectCollectionView];
    subjectCollectionView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [subjectCollectionView registerClass:[CTSubjectDetailCell class] forCellWithReuseIdentifier:@"cell"];
    [subjectCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ReusableView"];
    
    cameraBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cameraBtn.frame = CGRectMake((CT_HEADER_SCREEN_WIDTH-70)/2, CT_HEADER_SCREEN_HEIGHT-25-70, 70, 70);
    [cameraBtn addTarget:self action:@selector(cameraBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [cameraBtn setBackgroundImage:[UIImage imageNamed:@"camera"] forState:UIControlStateNormal];
    [self addSubview:cameraBtn];
}

#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return currentSelectedItem.list.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identify = @"cell";
    
    CTSubjectDetailCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    [cell sizeToFit];
    //    CTSubjectTimeLineItem * itm = (CTSubjectTimeLineItem *)[subjectArr objectAtIndex:indexPath.row];
    //    cell.imgUrl = itm.thumb;
    //    cell.name = itm.name;
    //    cell.describe = itm.tag_describe;
    //    if ([itm.tag_trends isEqualToString:@"0"])cell.isTrends = NO;
    //    else cell.isTrends = YES;
    //    if ([itm.tag_official isEqualToString:@"0"])cell.isOfficial = NO;
    //    else cell.isOfficial = YES;
    CTSubjectDetailItem * subItem = [[CTSubjectDetailItem alloc]init];
    subItem = [subjectDetailArray objectAtIndexedSubscript:indexPath.row];
    cell.imgUrl = subItem.url;
    return cell;
}

//头部显示的内容
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:
                                            UICollectionElementKindSectionHeader withReuseIdentifier:@"ReusableView" forIndexPath:indexPath];
    
        [headerView addSubview:subjectHeaderView];//头部广告栏
    return headerView;
}

#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return size;
    
}
//定义每个UICollectionView 的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(20,27,120,27);
}
//定义UICollectionView 每个item的纵向间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 20;
}

//定义每个UICollectionView 纵向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 3;
}

#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //CTSubjectTimeLineItem * itm = (CTSubjectTimeLineItem *)[subjectArr objectAtIndex:indexPath.row];
//    if ([self.delegate respondsToSelector:@selector(userPublishCollectionListViewClicked:)])
//    {
//        [self.delegate userPublishCollectionListViewClicked:self];
//    }
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

#pragma mark title Action
//头像
- (void)tagGestureHeadAction:(UITapGestureRecognizer *) sender
{
    if ([self.delegate respondsToSelector:@selector(headerBtnAction:withItem:)])
    {
        [self.delegate headerBtnAction:self withItem:currentSelectedItem];
    }
}
//分享
- (void)shareButtonAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(shareBtnAction:withShareUrl:)])
    {
        [self.delegate shareBtnAction:self withShareUrl:currentSelectedItem.share_url];
    }
}
//返回
- (void)backButtonAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(backBtnAction:)])
    {
        [self.delegate backBtnAction:self];
    }
}
//相机
- (void)cameraBtnAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(cameraBtnAction:)])
    {
        [self.delegate cameraBtnAction:self];
    }
}
//关注
- (void)attentionBtnAction:(UIButton *) sender
{
    if ([CTLogin isUserLoginState] == YES)
    {
        //        NSLog(@"111========%d",[CTLogin isUserLoginState]);
        if (attention_bool == NO)
        {
//            attentionBtn.hidden = YES;
//            attentionLabel.hidden = YES;
//            timeLabel.hidden = NO;
            [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_ok_bg"] forState:UIControlStateNormal];
            attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attentioned_title" withValue:nil withTable:@"Language"];
            attentionLabel.textColor = timeLabel.textColor;
            attention_bool = YES;
        }
        else  if ( attention_bool== YES)
        {
            //        timeLabel.hidden = YES;
            //        attentionBtn.hidden = NO;
            //        attentionLabel.hidden = NO;
            [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_bg"] forState:UIControlStateNormal];
            attentionLabel.text =[CTAppLanguage localizedStringForKey:@"fllow_attention_title" withValue:nil withTable:@"Language"];
            attentionLabel.textColor = CT_HEADER_GREEN_COLOR;
            attention_bool = NO;
        }
        
    }
    if ([self.delegate respondsToSelector:@selector(attentionBtnAction:withItem:withBool:)])
            {
                [self.delegate attentionBtnAction:self withItem:currentSelectedItem withBool:attention_bool];
            }
}
//- (void)attentionBtnAction:(UIButton *) sender
//{
//    
//    if (attention_bool == YES)
//    {
//        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_bg"] forState:UIControlStateNormal];
//        attentionLabel.textColor= CT_HEADER_GREEN_COLOR;
//        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attention_title" withValue:nil withTable:@"Language"];
//        attention_bool = NO;
//    }
//    else
//    {
//        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_ok_bg"] forState:UIControlStateNormal];
//        attentionLabel.textColor= CT_HEADER_DEEPLINE_COLOR;
//        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attentioned_title" withValue:nil withTable:@"Language"];
//        attention_bool = YES;
//    }
//    if ([self.delegate respondsToSelector:@selector(attentionBtnAction:withItem:withBool:)])
//    {
//        [self.delegate attentionBtnAction:self withItem:currentSelectedItem withBool:attention_bool];
//    }
//}

@end
